package org.ssmd3.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.ssmd3.pojo.User;
import org.ssmd3.service.UserService;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/admin")
public class AdminController {

    @Resource
    UserService userService;

    @RequestMapping("/login")
    public String login(){

        return "/slogin";
    }

    @RequestMapping("/dologin")
    public String dologin(Model model, HttpSession session, User user){

        User user1=userService.getUser(user.getUserName());
        if(user1!=null){
            if(user.getUserPassword().equals(user1.getUserPassword())){

//                在session里面添加用户状态信息
                session.setAttribute("uname",user1.getUserName());
                return "redirect:/home1/index";
//                return "forwards:/home/index";

            }else{
                model.addAttribute("error","密码错误！");
            }

        }else{
            model.addAttribute("error","该用户名不存在！");
        }

        return "/slogin";
    }
}
